package com.example.blogother.controller;

import com.alibaba.fastjson.JSONObject;
import com.xpd.blog.bean.LivesModel;
import com.xpd.blog.bean.Result;
import com.xpd.blog.bean.WeatherModel;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
@RestController
public class WeatherController {
    @RequestMapping("getWeather")
    public Result getWeather(){

        String url1 = "https://restapi.amap.com/v3/ip?key=73d4991acebdd39e191da9d1564c2dbb";
        String s1 = HttpsUtil.get(url1);
        JSONObject object1 = JSONObject.parseObject(s1);


       String adcode= object1.get("adcode").toString();
        System.out.println("adcode = " + adcode);
        String url = "https://restapi.amap.com/v3/weather/weatherInfo?city=430408&key=73d4991acebdd39e191da9d1564c2dbb&extensions=all";
        String s = HttpsUtil.get(url);
        System.out.println(s);
        JSONObject object = JSONObject.parseObject(s);
        WeatherModel jb = (WeatherModel)JSONObject.toJavaObject(object, WeatherModel.class);
       return new Result(1,"查询成功",object);
    }
}
